import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), "")

  return {
    base: env.BASE_URL,
    plugins: [react()],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, './src'),
        'libs': path.resolve(__dirname, './src/libs'),
        'components': path.resolve(__dirname, './src/components'),
      },
    },
    server: {
      proxy: {
        [env.API_PREFIX]: {
          target: env.API_URL,
          changeOrigin: true,
          // rewrite: (path) => path.replace(/^\/api/, '')
        }
      }
    },
    devServer: {
      client:
        {
          overlay:
            {
              errors: true,
              warnings: false,
              runtimeErrors: false
            }
        }
    },
    css: {
      // 对css的行为进行配置
      preprocessorOptions: {
        // key + config key代表预处理器的名
        less: {
          // 整个的配置对象都会最终给到less的执行参数（全局参数）中去
          // 在webpack里就给less-loader去配置就好了
          math: 'always',
          modifyVars: {
            '@primary-color': '#0B6BCB',//主题色
          },
          javascriptEnabled: true,
        }
      },

    },
  }
})
